package com.gxa.customer.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gxa.common.commons.R;
import com.gxa.common.params.AddHouseParam;
import com.gxa.common.params.QueryHouseParam;
import com.gxa.common.pojo.House;
import com.gxa.common.pojo.PartnerInfo;
import com.gxa.common.utils.RUtils;
import com.gxa.customer.mapper.HouseMapper;
import com.gxa.customer.service.HouseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;

@Service
public class HouseServiceImpl implements HouseService {
    @Autowired
    private HouseMapper houseMapper;
    @Override
    public R addHouse(AddHouseParam param) {
        House house = new House();
        BeanUtils.copyProperties(param,house);
        houseMapper.insert(house);
        return RUtils.success();
    }

    @Override
    public R delHouse(List<Integer> ids) {
        houseMapper.deleteBatchIds(ids);
        return RUtils.success();
    }

    @Override
    public R updateHouse(House house) {
        houseMapper.updateById(house);
        return RUtils.success();
    }

    @Override
    public R queryHouse(QueryHouseParam param) {
        if(Objects.nonNull(param.getId())){
            House house = houseMapper.selectById(param.getId());
            return RUtils.success(house);
        }
        if(Objects.nonNull(param.getNationId())&&Objects.nonNull(param.getForPrjectId())){
            QueryWrapper<House> wrapper = new QueryWrapper<>();
            wrapper.eq("nation_id",param.getNationId()).eq("for_project_id",param.getForPrjectId());
            List<House> list = houseMapper.selectList(wrapper);
            return RUtils.success(list);
        }
        return RUtils.fail();
    }
}
